﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

public class GameManager : MonoBehaviour
{
    [Header("开始按钮")]
    public Button startButton;

    [Header("游戏管理对象")]
    public GameObject game;

    [Header("返回按钮")]
    public Button returnButton;

    [Header("退出按钮")]
    public Button exitButton;

    [Header("时间文本")]
    public Text timeText;

    [Header("标题文本")]
    public Text titleText;

    [Header("提示文本")]
    public Text hintText;

    public float time;

    public bool isTime;

    public int timeInt;

    // Start is called before the first frame update
    void Start()
    {
        isTime = false;
        time = 30;
        game.gameObject.SetActive(false);
        returnButton.gameObject.SetActive(false);
        timeText.gameObject.SetActive(false);
        timeText.text = "时间:" + time.ToString();
        hintText.gameObject.SetActive(false);
        startButton.onClick.AddListener(StartBtnOnclick);
        returnButton.onClick.AddListener(ReturnButtonOnclick);
        exitButton.onClick.AddListener(ExitButtonOnclick);
    }

    // Update is called once per frame
    void Update()
    {
        if (isTime)
        {
            time -= Time.deltaTime;
            timeInt = (int)time;
            if (timeInt <= 0)
            {
                timeInt = 0;
                game.gameObject.SetActive(false);
                hintText.gameObject.SetActive(true);
            }
        }
        timeText.text = "时间:" + timeInt.ToString();
    }
    void ExitButtonOnclick()
    {
        Application.Quit();
    }
    void ReturnButtonOnclick()
    {
        isTime = false;
        time = 30;
        timeText.gameObject.SetActive(false);
        timeText.text = "时间:" + time.ToString();
        game.gameObject.SetActive(false);
        returnButton.gameObject.SetActive(false);
        hintText.gameObject.SetActive(false);
        startButton.gameObject.SetActive(true);
        titleText.gameObject.SetActive(true);
        exitButton.gameObject.SetActive(true);
    }
    void StartBtnOnclick()
    {
        time = 30;
        titleText.gameObject.SetActive(false);
        startButton.gameObject.SetActive(false);
        exitButton.gameObject.SetActive(false);
        returnButton.gameObject.SetActive(true);
        game.gameObject.SetActive(true);
        timeText.gameObject.SetActive(true);
        //DoTo:需要开始计时递减
        isTime = true;
    }
}
